package com.swipemaster.elements;

public class Collision
{
	public static int abs(int a)
	{
		if (a < 0)
		{
			return -a;
		}
		return a;
	}

	public static boolean isCircleCircle(int x, int y, int r, int x2, int y2, int r2)
	{
		final int dx = x - x2;
		final int dy = y - y2;
		return Math.round(Math.sqrt((dx * dx) + (dy * dy))) <= (r + r2);
	}

	public static boolean isRectCircle(int x, int y, int w, int h, int a, int b, int r)
	{
		final int dx = abs(x - a);
		final int dy = abs(y - b);
		if ((dx > (r + (w / 2))) || (dy > (r + (h / 2))))
		{
			return false;
		}
		if ((dx <= (w / 2)) || (dy <= (h / 2)))
		{
			return true;
		}
		final int cornerDist = ((dx - (w / 2)) * (dx - (w / 2))) + ((dy - (h / 2)) * (dy - (h / 2)));
		return cornerDist <= (r * r);
	}

	public static boolean isRectRect(int x, int y, int w, int h, int x2, int y2, int w2, int h2)
	{
		if (((x2 + (w2 / 2)) < (x - (w / 2))) || ((x2 - (w2 / 2)) > (x + (w / 2))) || ((y2 + (h2 / 2)) < (y - (h / 2)))
				|| ((y2 - (h2 / 2)) > (y + (h / 2))))
		{
			return false;
		}
		return true;
	}
}
